package com.itheima.info.manager.system.dao;

import com.itheima.info.manager.system.domain.Teacher;

/*
老师的 数据操作类
数组

增
删
改
查


 */
public class TeacherDao {
    private  Teacher[] teachers= new Teacher[10];
    //增
    public boolean addTeacher(Teacher teacher){
        for (int i = 0; i < teachers.length; i++) {
            Teacher teach = teachers[i];
            if(teach==null){
                teachers[i]=teacher;
                return true;
            }
        }
        return false;
    }
    //删
    public  void deleteTeacher(String sid){
        int index = getIndex(sid);
        teachers[index]=null;
    }
    //改
    public  void updateTeacher(String sid,Teacher teacher){
        int index = getIndex(sid);
        teachers[index]=teacher;
    }
    //查
    public Teacher[] findAllTeachers(){
        return teachers;
    }
    //根据工号找索引方法
    public int getIndex(String sid){
        for (int i = 0; i < teachers.length; i++) {
            Teacher teacher = teachers[i];
            if(teacher!=null&&teacher.getSid().equals(sid)){
                return i;
            }
        }
        return -1;
    }
}
